//按钮事件新增或编辑
var B4F9A7_type = "";
//其他页面传到本页面参数
var B4F9A7_param = {};
//暂时没用
var B4F9A7_validate = "";
//当前触发按钮
var B4F9A7_btn = "";

/*定义下拉框集合定义*/
/*declare select options begin*/
var B4F9A7_ary_ROLE_MAIN_ID = null;
var B4F9A7_ary_MENU_MAIN_ID = null;
var B4F9A7_ary_S_STATE = [{"MAIN_ID":"1","CN_NAME":"启用"},{"MAIN_ID":"0","CN_NAME":"禁用"}];

/*declare select options end*/

//输入框默认值
function B4F9A7_input_default(){
	//所有输入框设置默认值
	/*Input Default Begin*/
	$("#B4F9A7_S_STATE").val('1');
	/*Input Default End*/
}

//主从表传递参数
function B4F9A7_param_set(){
	/*Main Subsuv Table Param Begin*/
    $("#B4F9A7_find_ROLE_MAIN_ID_cn_name").val("");
    $("#B4F9A7_find_ROLE_MAIN_ID").val("-1");
    $("#B4F9A7_Clear_ROLE_MAIN_ID").show();
    $("#B4F9A7_Ope_ROLE_MAIN_ID").show();
    if(B4F9A7_param.hasOwnProperty("ROLE_MAIN_ID_cn_name"))
        $("#B4F9A7_find_ROLE_MAIN_ID_cn_name").val(s_decode(B4F9A7_param["ROLE_MAIN_ID_cn_name"]));
    if(B4F9A7_param.hasOwnProperty("ROLE_MAIN_ID"))
        $("#B4F9A7_ROLE_MAIN_ID").val(B4F9A7_param["ROLE_MAIN_ID"]);
    if(B4F9A7_param.hasOwnProperty("hidden_find") && B4F9A7_param.hasOwnProperty("ROLE_MAIN_ID_cn_name")){
        $("#B4F9A7_Ope_ROLE_MAIN_ID").hide();
        $("#B4F9A7_Clear_ROLE_MAIN_ID").hide();
    }
    $("#B4F9A7_find_MENU_MAIN_ID_cn_name").val("");
    $("#B4F9A7_find_MENU_MAIN_ID").val("-1");
    $("#B4F9A7_Clear_MENU_MAIN_ID").show();
    $("#B4F9A7_Ope_MENU_MAIN_ID").show();
    if(B4F9A7_param.hasOwnProperty("MENU_MAIN_ID_cn_name"))
        $("#B4F9A7_find_MENU_MAIN_ID_cn_name").val(s_decode(B4F9A7_param["MENU_MAIN_ID_cn_name"]));
    if(B4F9A7_param.hasOwnProperty("MENU_MAIN_ID"))
        $("#B4F9A7_MENU_MAIN_ID").val(B4F9A7_param["MENU_MAIN_ID"]);
    if(B4F9A7_param.hasOwnProperty("hidden_find") && B4F9A7_param.hasOwnProperty("MENU_MAIN_ID_cn_name")){
        $("#B4F9A7_Ope_MENU_MAIN_ID").hide();
        $("#B4F9A7_Clear_MENU_MAIN_ID").hide();
    }
	
	/*Main Subsuv Table Param end*/
    
	/*父页面查询条件参数传递至子页面并赋值*/
	/*Get Find Select param bgein*/
	if(B4F9A7_param.hasOwnProperty("ROLE_MAIN_ID"))
    	$("#B4F9A7_ROLE_MAIN_ID").val(B4F9A7_param["ROLE_MAIN_ID"]);
	if(B4F9A7_param.hasOwnProperty("ROLE_MAIN_ID_cn_name"))
    	$("#B4F9A7_find_ROLE_MAIN_ID_cn_name").val(B4F9A7_param["ROLE_MAIN_ID_cn_name"]);
	if(B4F9A7_param.hasOwnProperty("MENU_MAIN_ID"))
    	$("#B4F9A7_MENU_MAIN_ID").val(B4F9A7_param["MENU_MAIN_ID"]);
	if(B4F9A7_param.hasOwnProperty("MENU_MAIN_ID_cn_name"))
    	$("#B4F9A7_find_MENU_MAIN_ID_cn_name").val(B4F9A7_param["MENU_MAIN_ID_cn_name"]);
	
	/*Get Find Select param end*/	
}

//业务逻辑数据开始
function B4F9A7_t_content_role_link_biz_start(inputdata) {
	B4F9A7_param = inputdata;
	layer.close(ly_index);
    /*biz begin*/
    var inputdata = {
        "param_name": "N01_t_role_user_link$ROLE_MAIN_ID",
        "session_id": session_id,
        "login_id": login_id
    };
    ly_index = layer.load();
    get_ajax_baseurl(inputdata, "B4F9A7_get_N01_t_role_user_link$ROLE_MAIN_ID");
	
    /*biz end*/
}

/*biz step begin*/
function B4F9A7_format_ROLE_MAIN_ID(value, row, index) {
    var objResult = value;
    for(i = 0; i < B4F9A7_ary_ROLE_MAIN_ID.length; i++) {
        var obj = B4F9A7_ary_ROLE_MAIN_ID[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function B4F9A7_format_MENU_MAIN_ID(value, row, index) {
    var objResult = value;
    for(i = 0; i < B4F9A7_ary_MENU_MAIN_ID.length; i++) {
        var obj = B4F9A7_ary_MENU_MAIN_ID[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function B4F9A7_format_S_STATE(value, row, index) {
    var objResult = value;
    for(i = 0; i < B4F9A7_ary_S_STATE.length; i++) {
        var obj = B4F9A7_ary_S_STATE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}

function B4F9A7_get_N01_t_role_user_link$ROLE_MAIN_ID(input) {
    layer.close(ly_index);
    //查询失败
    if (Call_QryResult(input.N01_t_role_user_link$ROLE_MAIN_ID) == false)
        return false;
    B4F9A7_ary_ROLE_MAIN_ID = input.N01_t_role_user_link$ROLE_MAIN_ID;
    var inputdata = {
        "param_name": "N01_menu_content$menu_id",
        "session_id": session_id,
        "login_id": login_id
    };
    ly_index = layer.load();
    get_ajax_baseurl(inputdata, "B4F9A7_get_N01_menu_content$menu_id");
}

function B4F9A7_get_N01_menu_content$menu_id(input) {
    layer.close(ly_index);
    //查询失败
    if (Call_QryResult(input.N01_menu_content$menu_id) == false)
        return false;
    B4F9A7_ary_MENU_MAIN_ID = input.N01_menu_content$menu_id;

    if($("#B4F9A7_S_STATE").is("select") && $("#B4F9A7_S_STATE")[0].options.length == 0)
    {
        $.each(B4F9A7_ary_S_STATE, function (i, obj) {
            addOptionValue("B4F9A7_S_STATE", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
        });
    }
    B4F9A7_init_t_content_role_link();
}

/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

function B4F9A7_ROLE_MAIN_ID_cn_name_fun(){
    B4F9A7_btn = "ROLE_MAIN_ID"
    index_subhtml = "sys_vue/v_t_role.vue";
    random_subhtml = "AC096A";
    if(loadHtmlSubVueFun("sys_vue/v_t_role.vue","B4F9A7_t_content_role_link_call_vue") == true){
        var n = Get_RandomDiv("AC096A","");
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                $('#AC096A_v_t_role_Events').bootstrapTable('resetView');
                AC096A_param["ly_index"] = index;
                AC096A_param["target_name"] = "B4F9A7_find_"+B4F9A7_btn+"_cn_name";
                AC096A_param["target_id"] = "B4F9A7_"+B4F9A7_btn;
                AC096A_param["sourc_id"] = "MAIN_ID";
                AC096A_param["sourc_name"] = "ROLE_NAME";
            },
            end: function(){
                $(n).hide();
            }
        });
     }
}

function B4F9A7_MENU_MAIN_ID_cn_name_fun(){
    B4F9A7_btn = "MENU_MAIN_ID"
    index_subhtml = "dev_vue/v_menu_info.vue";
    random_subhtml = "A55264";
    if(loadHtmlSubVueFun("dev_vue/v_menu_info.vue","B4F9A7_t_content_role_link_call_vue") == true){
        var n = Get_RandomDiv("A55264","");
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                $('#A55264_v_menu_info_Events').bootstrapTable('resetView');
                A55264_param["ly_index"] = index;
                A55264_param["target_name"] = "B4F9A7_find_"+B4F9A7_btn+"_cn_name";
                A55264_param["target_id"] = "B4F9A7_"+B4F9A7_btn;
                A55264_param["sourc_id"] = "MAIN_ID";
                A55264_param["sourc_name"] = "MENU_NAME";
            },
            end: function(){
                $(n).hide();
            }
        });
     }
}

/*find qry fun end*/

/*页面结束*/
function B4F9A7_page_end(){
	if(B4F9A7_param["type"] == "edit"){
		B4F9A7_get_edit_info();
	}
}

//页面初始化方法
function B4F9A7_init_t_content_role_link() {
	//输入框默认值
	B4F9A7_input_default();
	//参数传递
	B4F9A7_param_set();	
	//表单验证
	B4F9A7_checkFormInput();
	//结束函数
	B4F9A7_page_end();
}

//提交表单数据
function B4F9A7_SubmitForm(){
	if(B4F9A7_param["type"] == "add"){
		var inputdata = {
				"param_name": "N01_ins_t_content_role_link",
				"session_id": session_id,
				"login_id": login_id
	            /*insert param begin*/
                ,"param_value1": $("#B4F9A7_ROLE_MAIN_ID").val()
                ,"param_value2": $("#B4F9A7_MENU_MAIN_ID").val()
                ,"param_value3": $("#B4F9A7_S_STATE").val()
				
	            /*insert param end*/
			};
		get_ajax_baseurl(inputdata, "B4F9A7_get_N01_ins_t_content_role_link");
	}
	else if(B4F9A7_param["type"] == "edit"){
		var inputdata = {
				"param_name": "N01_upd_t_content_role_link",
				"session_id": session_id,
				"login_id": login_id
	            /*update param begin*/
                ,"param_value1": $("#B4F9A7_ROLE_MAIN_ID").val()
                ,"param_value2": $("#B4F9A7_MENU_MAIN_ID").val()
                ,"param_value3": $("#B4F9A7_S_STATE").val()
                ,"param_value4": $("#B4F9A7_MAIN_ID").val()
				
	            /*update param end*/
			};
		get_ajax_baseurl(inputdata, "B4F9A7_get_N01_upd_t_content_role_link");
	}
}

//vue回调
function B4F9A7_t_content_role_link_call_vue(objResult){
	if(index_subhtml == "XXXXXX")
	{
		
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
    else if(index_subhtml == "sys_vue/v_t_role.vue"){
        var n = Get_RandomDiv("AC096A",objResult);
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                var inputdata = {
                    "type":B4F9A7_type,
                    "ly_index":index,
                    "target_name":"B4F9A7_find_ROLE_MAIN_ID_cn_name",
                    "target_id":"B4F9A7_ROLE_MAIN_ID",
                    "sourc_id":"MAIN_ID",
                    "sourc_name":"ROLE_NAME"
                };
                loadScript_hasparam("sys_vue/v_t_role.js","AC096A_v_t_role_biz_start",inputdata);
            },
            end: function(){
                $(n).hide();
            }
        });
    }
    else if(index_subhtml == "dev_vue/v_menu_info.vue"){
        var n = Get_RandomDiv("A55264",objResult);
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                var inputdata = {
                    "type":B4F9A7_type,
                    "ly_index":index,
                    "target_name":"B4F9A7_find_MENU_MAIN_ID_cn_name",
                    "target_id":"B4F9A7_MENU_MAIN_ID",
                    "sourc_id":"MAIN_ID",
                    "sourc_name":"MENU_NAME"
                };
                loadScript_hasparam("dev_vue/v_menu_info.js","A55264_v_menu_info_biz_start",inputdata);
            },
            end: function(){
                $(n).hide();
            }
        });
    }
	
	/*get find subvue end*/
}

//for表单提交
$("#B4F9A7_save_t_content_role_link_Edit").click(function () {
	$("form[name='B4F9A7_DataModal']").submit();
})

/*修改数据*/
function B4F9A7_get_N01_upd_t_content_role_link(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_upd_t_content_role_link) == true)
	{
		swal("修改数据成功!", "", "success");
		A4F9A7_t_content_role_link_query();
		B4F9A7_clear_validate();
		layer.close(B4F9A7_param["ly_index"]);
	}
}

/*添加数据*/
function B4F9A7_get_N01_ins_t_content_role_link(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_ins_t_content_role_link) == true)
	{
		swal("添加数据成功!", "", "success");
		A4F9A7_t_content_role_link_query();
		B4F9A7_clear_validate();
		layer.close(B4F9A7_param["ly_index"]);
	}
}

//取消编辑
$("#B4F9A7_cancel_t_content_role_link_Edit").click(function () {
	layer.close(B4F9A7_param["ly_index"]);
	B4F9A7_clear_validate();
	$("[id^='B4F9A7_div']").hide();
})

//清除查找框
function B4F9A7_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//清除验证缓存
function B4F9A7_clear_validate(){
	$("#B4F9A7_DataModal").find(".has-error").each(function(){
		$(this).removeClass('has-error');
	});
	$("#B4F9A7_DataModal").find(".has-success").each(function(){
	 	$(this).removeClass('has-success');
	});
	$("#B4F9A7_DataModal").find(".glyphicon").each(function(){
	 	$(this).remove();
	});
}

//输入框重置
function B4F9A7_clear_edit_info(){
	var inputs = $("#B4F9A7_DataModal").find('input');
	var selects = $("#B4F9A7_DataModal").find("select");
	var textareas = $("#B4F9A7_DataModal").find('textarea');
	var divs = $("div[id^='B4F9A7'][id$='FILE_div']");  
	$.each(inputs, function (i, obj) {
		$(obj).val("");
	});
	$.each(selects, function (i, obj) {
		$(obj).val("");
	});
	$.each(textareas, function (i, obj) {
		$(obj).val("");
	});
	$.each(divs, function (i, obj) {
		$(obj).html("");
	});
	/*清除输入框验证信息*/
	/*input validate clear begin*/
    B4F9A7_clear_input_cn_name('B4F9A7_find_ROLE_MAIN_ID_cn_name','B4F9A7_ROLE_MAIN_ID')
    B4F9A7_clear_input_cn_name('B4F9A7_find_MENU_MAIN_ID_cn_name','B4F9A7_MENU_MAIN_ID')
	
	/*input validate clear end*/
	B4F9A7_init_t_content_role_link();
}

//页面输入框赋值
function B4F9A7_get_edit_info(){
	var rowData = $("#A4F9A7_t_content_role_link_Events").bootstrapTable('getData')[A4F9A7_select_t_content_role_link_rowId];
	var inputs = $("#B4F9A7_DataModal").find('input');
	var selects = $("#B4F9A7_DataModal").find("select");
	var textareas = $("#B4F9A7_DataModal").find('textarea');
	
	//通用子页面输入框赋值
	Com_edit_info(rowData,inputs,selects,textareas,"A4F9A7","B4F9A7");
	
	/*文件附件格式*/
	/*input param fileinfo begin*/
	
	/*input param fileinfo end*/
}

//form验证
function B4F9A7_checkFormInput() {
    B4F9A7_validate = $("#B4F9A7_DataModal").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        rules: {
        	/*input check rules begin*/
            B4F9A7_MAIN_ID: {}
            ,B4F9A7_ROLE_MAIN_ID: {}
            ,B4F9A7_MENU_MAIN_ID: {}
            ,B4F9A7_S_STATE: {}
			
            /*input check rules end*/
        },
        messages: {
        	/*input check messages begin*/
            B4F9A7_MAIN_ID: {}
            ,B4F9A7_ROLE_MAIN_ID: {}
            ,B4F9A7_MENU_MAIN_ID: {}
            ,B4F9A7_S_STATE: {}
			
            /*input check messages end*/
        },
        errorPlacement: function (error, element) {
            element.next().remove();
            element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
            element.closest('.form-group').append(error);
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error has-feedback');
        },
        success: function (label) {
            var el = label.closest('.form-group').find("input");
            el.next().remove();
            el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
            label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
            label.remove();
        },
        submitHandler: function (form) {
        	B4F9A7_SubmitForm();
        	return false;
        }
    })
}